<template>
    <div class="post-header">
        <div v-if="showBreadCrumb" class="breadcrumb">
            <el-breadcrumb class="breadcrumb-href" separator-class="el-icon-arrow-right">
                <el-breadcrumb-item v-for="path in paths" :key="path.path" :to="{path: path.href}">
                    {{path.title}}
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="center-flex-box">
            <el-pagination
                @current-change="handleCurrentChange"
                :current-page.sync="pageInfo.page"
                :page-size="pageInfo.size"
                layout="total, prev, pager, next, jumper"
                :total="pageInfo.total">
            </el-pagination>
        </div>
        <div class="post-back center-flex-box">
            <a class="post-back-a" @click="back">后退</a>
        </div>
    </div>
</template>

<script>
    export default {
        name: 'pageBar',
        data () {
            return {
                paths: []
            }
        },
        props: {
            pageInfo: Object,
            showBreadCrumb: {
                type: Boolean,
                required: false,
                default: false
            }
        },
        mounted () {
            this.resolvePath()
        },
        methods: {
            handleCurrentChange (val) {
                this.$emit('query')
            },
            resolvePath () {
                let path = this.$route.path
                let arr = path.split('/')
                let paths = []
                let href = ''
                arr.forEach(value => {
                    if (value !== '') {
                        href = href + '/' + value
                        paths.push({
                            href,
                            title: value.toUpperCase()
                        })
                    }
                })
                this.paths = paths
            },
            back () {
                this.$router.go(-1)
            }
        }
    }
</script>

<style lang="scss" scoped>
    .center-flex-box {
        vertical-align: top;
        display: -webkit-inline-flex;
        justify-content: center;
        align-items: center;
    }

    .post-header {
        .breadcrumb {
            float: left;
            width: 30%;
            height: 100%;

            .breadcrumb-href {
                line-height: 36px;
            }
        }

        .post-back {
            float: right;
            width: 20%;

            .post-back-a {
                font-size: 12px;
                line-height: 32px;
                color: #6159ff;
            }

            a {
                text-decoration: none;
                cursor: pointer;
            }

            a:link {
                color: #6159ff;
            }

            a:visited {
                color: #6159ff;
            }

            a:hover {
                color: rgba(255, 151, 60, 0.8);
            }

            a:active {
                color: rgba(255, 86, 25, 0.8);
            }
        }
    }
</style>
